package com.retail.sms.config;

import lombok.extern.log4j.Log4j2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.annotation.PostConstruct;

/**
 * @Package：com.bw.sms.config
 * @name：RabbitConfig
 */
@Configuration
@Log4j2
public class RabbitConfig{

    // 队列1
    public static final String Queue = "QUEUE_NAME";
    // 交换机1
    public static final String DIRECT_EXCHANGE = "DIRECT_EXCHANGE_NAME";
    // 路由建1
    public static final String ROUTE = "ROUTE_KEY";

    @Bean
    public Queue queue() {
        return new Queue(Queue);
    }

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(directExchange()).with(ROUTE);
    }

    // 队列2
    public static final String Queue_TWO = "QUEUE_NAME_TWO";
    // 交换机2
    public static final String DIRECT_EXCHANGE_TWO = "DIRECT_EXCHANGE_NAME_TWO";
    // 路由建2
    public static final String ROUTE_TWO = "ROUTE_KEY_TWO";

    @Bean
    public Queue queue2() {
        return new Queue(Queue_TWO);
    }

    @Bean
    public DirectExchange directExchange2() {
        return new DirectExchange(DIRECT_EXCHANGE_TWO);
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(queue2()).to(directExchange2()).with(ROUTE_TWO);
    }

    public static final Logger logger = LoggerFactory.getLogger(RabbitConfig.class);
}
